package com.huike.review.service.impl;

import com.github.pagehelper.IPage;
import com.github.pagehelper.Page;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.exception.CustomException;
import com.huike.common.utils.bean.BeanUtils;
import com.huike.review.pojo.PageBean;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import com.huike.review.mapper.MybatisReviewMapper;
import com.huike.review.vo.MybatisReviewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * mybatis复习使用的业务层
 * 注意该业务层和我们系统的业务无关，主要是让同学们快速熟悉系统的
 */
@Service
public class ReviewServiceImpl implements ReviewService {

    @Autowired
    private MybatisReviewMapper reviewMapper;

    @Override
    public int addreview(String name, Integer age, String sex) {
        int row = reviewMapper.insertReview(name,age,sex);

        return row;
    }

    @Override
    public int update(Review review) {
        int row = reviewMapper.update(review);
        return row;
    }

    @Override
    public int deleteById(Long id) {

        int row = reviewMapper.deleteById(id);

        return row;
    }

    @Override
    public Review selectById(Long id) {

        Review review = reviewMapper.selectById(id);
        return review;
    }

    @Override
    public PageBean findPage(Integer pageNum, Integer pageSize) {
        Integer page=(pageNum-1)*pageSize;
        List<Review> list = reviewMapper.findPage(page, pageSize);
        int total = reviewMapper.findcount();

        PageBean pageBean = new PageBean();
        pageBean.setRows(list);
        pageBean.setTotal(total);

        return pageBean;
    }


}
